package com.wjzjq.hiring.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;

/**
 * Servlet Filter implementation class LoginFilter
 */
@WebFilter(filterName = "LoginFilter", urlPatterns = { "/*" }, initParams = {
		@WebInitParam(name = "noLoginPaths", value = "login.jsp") })
public class LoginFilter implements Filter {
	private FilterConfig config;

	public void init(FilterConfig fConfig) throws ServletException {
		// 初始化的时候就赋值
		config = fConfig;
	}

	public void destroy() {
	}

	public void doFilter(ServletRequest a, ServletResponse b, FilterChain chain) throws IOException, ServletException {
		// HttpServletRequest request = (HttpServletRequest) a;
		// HttpServletResponse response = (HttpServletResponse) b;
		// HttpSession session = request.getSession();
		// request.setCharacterEncoding("utf-8");
		// if (session.getAttribute("talent") == null) {
		// response.sendRedirect(request.getContextPath() +
		// "/TalentServlet?command=login");
		// } else {
		chain.doFilter(a, b);
		// }
		// String noLoginPaths = config.getInitParameter("noLoginPaths");
		// if (noLoginPaths != null) {
		// String[] strArray = noLoginPaths.split(";");
		// for (int i = 0; i < strArray.length; i++) {
		// if (strArray[i] == null || "".equals(strArray[i]))
		// continue;
		// if (request.getRequestURI().indexOf(i) != -1) {
		// chain.doFilter(a, b);
		// return;
		// }
		// }
		// }
	}

}
